package com.atguigu3.common_algorithm.exer1;

/**
 * ClassName: ArrayExer1
 * Package: com.atguigu3.common_algorithm.exer1
 * Description:
 *
 * @Author 姜
 * @Create 2023/11/14 16:33
 * @Version 1.0
 */
public class ArrayExer1 {
    public static void main(String[] args) {
        // 1. 动态初始化方式创建数组
        int[] arr = new int[10];
        // 2. 通过循环给数组元素赋值
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * (99 - 10 + 1)) + 10;
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
        // 3.1 最大值
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        System.out.println("最大值为：" + max);
        // 3.2 最小值
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println("最小值为" + min);

        // 3.3 总和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("总和为" + sum);

        // 3.4 平均值
        System.out.println("平均值为" + sum / arr.length);
    }
}
